home *** CD-ROM | disk | FTP | other *** search
- #include "Painterly.h"
- #include "DialogUtils.h"
-
- extern DocumentRecord gDstDoc; /* The doc record for the destination */
- extern CWindowPtr gDstWindPtr; /* the destination window */
- extern GWorldPtr gUndoBuffer;
- extern short gOrderedIncrement;
- extern Boolean gRandomStrokes;
-
- /* Protos for a couple internal (to this file) routines */
- pascal void DimIt(WindowPtr dwind, short dinum);
- pascal Boolean TabFilter(DialogPtr dptr, EventRecord *event, short *item);
-
- /* This is the Pen Size dialog */
- void PenDlog(void)
- {
- DialogPtr dptr;
- short hit, kind;
- Handle itmhndl;
- Rect rect;
- PenState thePen;
- CGrafPtr oldport;
- GDHandle olddev;
-
- #define PENX 4 /* The Pen Width text item */
- #define PENY 5 /* The Pen Height text item */
-
- /* Save the current port and device */
- GetGWorld(&oldport, &olddev);
-
- /* Get the dialog (invisible) */
- dptr = GetNewDialog(kPenDlogID, nil, (Ptr)(-1));
- if(dptr == nil)
- {
- DoErrorAlert(kNoResStr, 0);
- return;
- }
-
- /* OK button Outline */
- GetDItem(dptr, kOKOutline, &kind, &itmhndl, &rect);
- SetDItem(dptr, kOKOutline, userItem, (Handle)BtnItem, &rect);
-
- /* Other user Items... */
-
- /* Set Values of text items... */
- SetGWorld(gDstDoc.world, nil);
- GetPenState(&thePen);
- ShortToDlog(thePen.pnSize.h, dptr, PENX);
- ShortToDlog(thePen.pnSize.v, dptr, PENY);
- SetGWorld(oldport, olddev);
-
- /* Do it... */
- SelIText(dptr, PENX, 0, 32767);
- ShowWindow(dptr);
- while(true) /* Loop until break...*/
- {
- Boolean out = false;
-
- ModalDialog(NumFilter, &hit); /* Num Filter only allows numeric input */
- switch(hit)
- {
- case kOKButton: /* OK button hit...*/
- if(InRange(dptr, PENX, 1, 100))
- {
- if(InRange(dptr, PENY, 1, 100))
- {
- short penx, peny;
-
- /* Need to set the pen size in both destination ports AND
- the Undo buffer, if it exists, since the user may switch
- to it at any time by doing an undo */
- penx = DlogToShort(dptr, PENX);
- peny = DlogToShort(dptr, PENY);
-
- SetGWorld(gDstWindPtr, olddev);
- PenSize(penx, peny);
- SetGWorld(gDstDoc.world, nil);
- PenSize(penx, peny);
- if(gUndoBuffer != nil)
- {
- SetGWorld(gUndoBuffer, nil);
- PenSize(penx, peny);
- }
- SetGWorld(oldport, olddev);
- out = true;
- }
- }
- break;
-
- case kCancelButton: /* Cancel button hit...*/
- out = true;
- break;
-
- default: /* Anything else hit... */
- continue;
- }
- if(out)
- break;
- }
- InitCursor();
- DisposDialog(dptr);
- }
-
- void AutoPaintSetupDlog(void)
- {
- DialogPtr dptr;
- short hit, kind;
- Handle itmhndl;
- Rect rect;
-
- #define kIncAmnt 6 /* The text item for the no. of pixels to skip */
- #define kRandRad 7 /* The "Random Strokes" radio button */
- #define kOrdRad 8 /* The "Ordered Strokes" radio button */
- #define kGrayBox 9 /* A user item that covers the stuff we may need to gray out */
- #define kDummyItem 10 /* A text item that is outside the visible dialog window: when
- the visible text item is grayed out, this one is selected to
- hide the insertion point. Otherwise you get a flashing
- insertion point in the grayed item, which looks wierd */
-
- dptr = GetNewDialog(kAutoPaintID, nil, (Ptr)(-1));
- if(dptr == nil)
- {
- DoErrorAlert(kNoResStr, 0);
- return;
- }
-
- /* OK button Outline */
- GetDItem(dptr, kOKOutline, &kind, &itmhndl, &rect);
- SetDItem(dptr, kOKOutline, userItem, (Handle)BtnItem, &rect);
-
- /* The dimming Box */
- GetDItem(dptr, kGrayBox, &kind, &itmhndl, &rect);
- SetDItem(dptr, kGrayBox, userItem, (Handle)DimIt, &rect);
-
- /* Set Values...the true gOrderedIncrement is one more than the number of pixels to
- skip, which is what the user enters. This is because gOrderedIncrement is added to
- the previous point */
- ShortToDlog(gOrderedIncrement - 1, dptr, kIncAmnt);
-
- GetDItem(dptr, kRandRad, &kind, &itmhndl, &rect);
- SetCtlValue(itmhndl, gRandomStrokes ? 1 : 0);
-
- GetDItem(dptr, kOrdRad, &kind, &itmhndl, &rect);
- SetCtlValue(itmhndl, gRandomStrokes ? 0 : 1);
-
- if(gRandomStrokes)
- SelIText(dptr, kDummyItem, 0, 0);
- else
- SelIText(dptr, kIncAmnt, 0, 32767);
-
- /* Do it... */
- ShowWindow(dptr);
- while(true) /* Loop until break...*/
- {
- Boolean out = false;
-
- ModalDialog(TabFilter, &hit);
- switch(hit)
- {
- case kOKButton: /* OK button hit...*/
- GetDItem(dptr, kRandRad, &kind, &itmhndl, &rect);
- gRandomStrokes = (GetCtlValue(itmhndl) ? true : false);
- if(gRandomStrokes == false)
- {
- if(InRange(dptr, kIncAmnt, 0, 1000))
- {
- gOrderedIncrement = DlogToShort(dptr, kIncAmnt) + 1;
- out = true;
- }
- }
- else
- out = true;
- break;
-
- case kCancelButton: /* Cancel button hit...*/
- out = true;
- break;
-
- case kRandRad: /* Radio button hit...*/
- case kOrdRad:
- GetDItem(dptr, hit, &kind, &itmhndl, &rect);
- if(GetCtlValue(itmhndl) == 0)
- {
- SetCtlValue(itmhndl, 1);
- GetDItem(dptr, (hit == kRandRad ? kOrdRad : kRandRad), &kind, &itmhndl, &rect);
- SetCtlValue(itmhndl, (GetCtlValue(itmhndl) ? 0 : 1));
- GetDItem(dptr, kGrayBox, &kind, &itmhndl, &rect);
- SetPort(dptr);
- InvalRect(&rect);
- if(hit == kRandRad) /* disabling text item */
- {
- SelIText(dptr, kDummyItem, 0, 0);
- }
- else
- SelIText(dptr, kIncAmnt, 0, 32767);
-
- }
- continue;
-
- default: /* Anything else hit... */
- continue;
- }
- if(out)
- break;
- }
- InitCursor();
- DisposDialog(dptr);
- }
-
- /* This userItem dims itself (and anything under it) if the kRandRad radio button is
- on */
- pascal void DimIt(WindowPtr dwind, short dinum)
- {
- ControlHandle tempCont;
-
- tempCont = SnatchHandle(dwind, kRandRad);
- if (GetCtlValue(tempCont) == 1)
- {
- PenState thePen;
- short itemType;
- Handle itemHandle;
- Rect dimRect;
-
- GetPenState(&thePen);
- GetDItem(dwind, dinum, &itemType, &itemHandle, &dimRect);
- PenMode(notPatBic);
- PenPat(qd.gray);
- PaintRect(&dimRect);
- SetPenState(&thePen);
- }
- }
-
- pascal Boolean TabFilter(DialogPtr dptr, EventRecord *event, short *item)
- {
- char theKey;
- Boolean returnVal = false, grayed;
- short hit, kind;
- Handle itmhndl;
- Rect rect;
-
- /* If the edit text isn't grayed out, Change the cursor to an I Beam if it's over
- the active editText item */
- grayed = GetCtlValue(SnatchHandle(dptr, kRandRad));
- if(!grayed)
- IBeamIt(dptr);
-
- /* Standard key filtering */
- returnVal = StdKeyFilter(dptr, event, item);
-
- /* if that didn't handle it... */
- if(returnVal == false)
- {
- /* If the edit text is grayed out, capture mouseDowns in the edit item to
- prevent the user activating it */
- if(grayed)
- {
- if(event->what == mouseDown)
- {
- Point here;
-
- here = event->where;
- SetPort(dptr);
- GlobalToLocal(&here);
- GetDItem(dptr, kIncAmnt, &kind, &itmhndl, &rect);
- if(PtInRect(here, &rect))
- returnVal = true;
- }
- }
- }
-
- /* if that didn't handle it, look at keydowns. Trap tabs if the text is grayed out
- so the user can't tab into it, otherwise allow only numeric input if the text
- is active*/
- if(returnVal == false && ( event->what == keyDown || event->what == autoKey ))
- {
- theKey = event->message & charCodeMask;
- if(grayed)
- {
- if(theKey == kTabKey)
- {
- /* If the Random Radio Button is set, then don't let Tab key
- go to edit text box */
- if(grayed)
- returnVal = true;
- }
- }
- else
- {
- /* We're only allowing numeric characters */
- if(theKey > kLastCntrlKey && theKey < kDeleteKey) /* Printable Ascii? */
- {
- if (theKey < '0' || theKey > '9') /* not a number */
- {
- SysBeep(1); /* complain a little */
- returnVal = true;
- }
- }
- else
- returnVal = false;
- }
- }
- return(returnVal);
- }
-
- /* The alert that appears if the offworlds are less than 32 bits deep */
- void DepthAlert(short offdepth)
- {
- Str255 depthStr, colorsStr;
- long colors;
-
- NumToString((long)offdepth, depthStr);
- colors = 1L << offdepth;
- NumToString(colors, colorsStr);
- ParamText(colorsStr, depthStr, nil, nil);
- NoteAlert(kDepthAlertID, nil);
- }
-
- /* Puts up the "Save Changes?" dialog, and returns the number of the button hit */
- short SaveChangesDlog(void)
- {
- Str255 fileName;
- DialogPtr dptr;
- short hit, kind;
- Handle itmhndl;
- Rect rect;
- Boolean rslt = false;
-
- #define NOSAVEBUTTON 4
-
- /* Get the title of the front window, and use ParamText to set it in
- the dialog */
- GetWTitle(FrontWindow(), fileName);
- ParamText(fileName, "\p", "\p", "\p");
-
- dptr = GetNewDialog(kSaveChangesDlogID, nil, (Ptr)(-1));
- if(dptr == nil)
- {
- DoErrorAlert(kNoResStr, 0);
- return kCancelButton;
- }
-
- /* OK button Outline */
- GetDItem(dptr, kOKOutline, &kind, &itmhndl, &rect);
- SetDItem(dptr, kOKOutline, userItem, (Handle)BtnItem, &rect);
-
- /* Do it... */
- ShowWindow(dptr);
- while(true) /* Loop until break...*/
- {
- Boolean out = false;
-
- ModalDialog(StdKeyFilter, &hit);
- switch(hit)
- {
- case kOKButton:
- case kCancelButton:
- case NOSAVEBUTTON:
- rslt = hit;
- out = true;
- break;
-
- default: /* Anything else hit... */
- continue;
- }
- if(out)
- break;
- }
- InitCursor();
- DisposDialog(dptr);
- return rslt;
- }
-
-